import React, { Component } from 'react'
import { Link } from 'react-router-dom'
import './head.scss'
import phone from '../../../img2/phone.png'
import arrowdown from '../../../img3/arrow-r.png'

import cartMehtod from '../../../publicMethod.js'
export default class head extends Component {
    constructor(props) {
        super(props)
        this.state={
            name:'',
            islogin:false
        }
    }
    componentDidMount(){
        this.setState({
            islogin:localStorage.getItem('user_info')?true:false,
            name:localStorage.getItem('user_info')?JSON.parse(localStorage.getItem('user_info')).nickName:''
        })
    }
    exit(){
        localStorage.removeItem('user_info');
        this.props.history.push('/action');
    }
    tocity(){
        this.props.history.push('/producthome/changecity');
    }
    render() {
        return (
            <div >
                <div className="he">
                <div className="head">
                    <div className="head-l" onClick={this.tocity.bind(this)}>所在城市：<span>{cartMehtod.city}</span>&nbsp;<img src={arrowdown} alt=""/></div>
                    <div className="head-r">
                        {this.state.islogin?( <span>你好，<i>{this.state.name}</i><Link to='###'className="ss" onClick={this.exit.bind(this)} >退出</Link></span>):(
                            <span><Link to='/loginmima'>登录</Link>
                            <Link to='/register'>注册</Link></span>
                        )}
                       
                        
                        <Link to='/people/myorderlist'>我的订单</Link>
                            <Link to='/people/mymessage'>我的消息</Link>
                            <Link to='/producthome/woshishangjia'>我是商家</Link>
                        <span><img src={phone}/> 400-800-8820</span>
                    </div>
                </div>
                </div>
                
            </div>
        )
    }
}
